home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / picturedt / rect.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-19  |  2.4 KB  |  142 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // rect.cpp
  3. //
  4. // Jeffry A Worth
  5. // November 10, 1995
  6. //////////////////////////////////////////////////////////////////////////////
  7.  
  8. //////////////////////////////////////////////////////////////////////////////
  9. // INCLUDES
  10. #include "aframe:include/rect.hpp"
  11.  
  12. //////////////////////////////////////////////////////////////////////////////
  13. //
  14.  
  15. AFPoint::AFPoint(LONG x, LONG y)
  16. {
  17.     m_x = x;
  18.     m_y = y;
  19. }
  20.  
  21. void AFPoint::SetPoint(LONG x, LONG y)
  22. {
  23.     m_x = x;
  24.     m_y = y;
  25. }
  26.  
  27. void AFPoint::SetPoint(AFPoint* point)
  28. {
  29.     m_x = point->m_x;
  30.     m_y = point->m_y;
  31. }
  32.  
  33. AFPoint* AFPoint::operator+=(AFPoint* point)
  34. {
  35.     m_x+=point->m_x;
  36.     m_y+=point->m_y;
  37.     return this;
  38. }
  39.  
  40. AFPoint* AFPoint::operator+=(AFPoint point)
  41. {
  42.     m_x+=point.m_x;
  43.     m_y+=point.m_y;
  44.     return this;
  45. }
  46.  
  47. AFPoint* AFPoint::operator-=(AFPoint* point)
  48. {
  49.     m_x-=point->m_x;
  50.     m_y-=point->m_y;
  51.     return this;
  52. }
  53.  
  54. AFPoint* AFPoint::operator-=(AFPoint point)
  55. {
  56.     m_x-=point.m_x;    
  57.     m_y-=point.m_y;
  58.     return this;
  59. }
  60.  
  61. AFRect::AFRect(ULONG x1, ULONG y1, ULONG x2, ULONG y2)
  62. {
  63.   m_TopLeft.SetPoint(x1,y1);
  64.   m_BottomRight.SetPoint(x2,y2);
  65. }
  66.  
  67. AFRect::AFRect()
  68. {
  69.   m_TopLeft.SetPoint(0,0);
  70.   m_BottomRight.SetPoint(0,0);
  71. }
  72.  
  73. void AFRect::SetRect(ULONG x1, ULONG y1, ULONG x2, ULONG y2)
  74. {
  75.   m_TopLeft.SetPoint(x1,y1);
  76.   m_BottomRight.SetPoint(x2,y2);
  77. }
  78.  
  79. void AFRect::SetRect(AFPoint* tl, AFPoint* br)
  80. {
  81.   m_TopLeft.SetPoint(tl);
  82.   m_BottomRight.SetPoint(br);
  83. }
  84.  
  85. AFPoint* AFRect::TopLeft()
  86. {
  87.   return &m_TopLeft;
  88. }
  89.  
  90. AFPoint* AFRect::BottomRight()
  91. {
  92.   return &m_BottomRight;
  93. }
  94.  
  95. ULONG AFRect::Width()
  96. {
  97.   if(m_BottomRight.m_x > m_TopLeft.m_x)
  98.     return m_BottomRight.m_x - m_TopLeft.m_x;
  99.   return m_TopLeft.m_x - m_BottomRight.m_x;
  100. }
  101.  
  102. ULONG AFRect::Height()
  103. {
  104.   if(m_BottomRight.m_y > m_TopLeft.m_y)
  105.     return m_BottomRight.m_y - m_TopLeft.m_y;
  106.   return m_TopLeft.m_y - m_BottomRight.m_y;
  107. }
  108.  
  109. AFRect* AFRect::operator+=(AFPoint* point)
  110. {
  111.     m_TopLeft+=point;
  112.     m_BottomRight+=point;
  113.     return this;
  114. }
  115.  
  116. AFRect* AFRect::operator+=(AFPoint point)
  117. {
  118.     m_TopLeft+=point;
  119.     m_BottomRight+=point;
  120.     return this;
  121. }
  122.  
  123. AFRect* AFRect::operator-=(AFPoint* point)
  124. {
  125.     m_TopLeft-=point;
  126.     m_BottomRight-=point;
  127.     return this;
  128. }
  129.  
  130. AFRect* AFRect::operator-=(AFPoint point)
  131. {
  132.     m_TopLeft-=point;
  133.     m_BottomRight-=point;
  134.     return this;
  135. }
  136.  
  137. AFRect* AFRect::operator=(AFRect* rect)
  138. {
  139.     SetRect(rect->TopLeft(),rect->BottomRight());
  140.     return this;
  141. }
  142.